//源码
import { debounce } from '@ide/utils/tools';
import { createPostChannel, createPostFormDataChannel, createGetChannelBlob, createGetChannel, buildWebsocket, Fetch } from './request';
// import Mock from './mock';
export interface SessionContent{
  'currentFile'?: string;
  'fileTree'?: string[];
  'files'?: string[];
  'layout'?: {
    'side'?: {
      'size'?: number;
      'state'?: string;
    };
    'sideRight'?: {
      'size'?: number;
      'state'?: string;
    };
    'bottom'?: {
      'size'?: number;
      'state'?: string;
    }
  }
}
// export const getUser = Mock.get(); // createGetChannel('api/v1/user/info/get');
export const getConfig = createGetChannel('getUserConfig');

export const logOut = createPostChannel('logout');
// export const index = createPostChannel('index');
export const getContractFiles = createPostChannel('files');
export const goModuleFiles = createPostChannel('goModuleFiles');
export const newFile = createPostChannel('file/new');
export const file = createPostChannel('file');
export const outline = createPostChannel('outline');
export const saveFile = createPostChannel('file/save');
export const build = createPostChannel('build');
export const fmt = createPostChannel('go/fmt');
export const importFiles = createPostFormDataChannel('file/import');
export const exportFile = createPostChannel('file/7z/new');

export const autocomplete = createPostChannel('autocomplete');

export const removeFile = createPostChannel('file/remove');
export const renameFile = createPostChannel('file/rename');
export const contractHasBuild = createPostChannel('contractHasBuild');

export const contractNames = createPostChannel('compileDirectory');
export const contractMethod = createPostChannel('dockergo/method');

export const deployContractList = createPostChannel('deploy/contractList');
export const contractRunBuild = createPostChannel('buildAll');
export const contractInvokeAll = createPostChannel('invokeAll');
export const contractCompile = createPostChannel('cross');

export const getContractFile = createGetChannelBlob('file/getContractFile');
export const deployContract = createPostChannel('deploy');
export const hasDeployContractList = createPostChannel('deploy/hasDeployContractList');
export const preference = createPostChannel('preference');
export const pullnotify = createPostChannel('pullnotify');
export const newContract = createPostChannel('new/contract');

export const decl = createPostChannel('find/decl');

export const outputWs = buildWebsocket('output/ws');
export const accountWs = buildWebsocket('notification/ws');
export const filesWs = buildWebsocket('session/ws');
export const getTemplateContracts = createPostChannel('contracts/getTemplateContracts');
export const deleteBuild = createPostChannel('deploy/deleteBuild');
export const deleteDeploy = createPostChannel('deploy/deleteDeploy');
export const sessionSave:Fetch<SessionContent, any> = createPostChannel('session/save');
export const audit = createPostChannel('auditContract');
export const getHiddenList = createPostChannel('contracts/getHiddenList');
export const setHiddenStatus = createPostChannel('contracts/setHiddenStatus');
// 同步ide状态添加防抖
export const updateSessionDebounce = debounce((arg) => {
  sessionSave(arg);
}, 1000);
// build文件防抖
export const buildDebounce = debounce((arg) => {
  build(arg);
}, 1000);
